package com.ycsj.goldmedalnewconcept.student.adapter;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.student.bean.ScoreInfo;

import java.util.List;

/**
 * Created by Administrator on 2019/5/8 0008.
 */

public class ScoreAdapter extends BaseQuickAdapter<ScoreInfo.ScoreListBean, BaseViewHolder> {

    public ScoreAdapter(int layoutResId, @Nullable List<ScoreInfo.ScoreListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ScoreInfo.ScoreListBean item) {
        //单元
        TextView tvUnit = helper.getView(R.id.tv_unit);

        if (!TextUtils.isEmpty(getUnit(item.lesson_id))) {
            tvUnit.setText("U" + getUnit(item.lesson_id));
        } else {
            tvUnit.setText("无");
        }

        //名称--预习检测
        TextView tvName = helper.getView(R.id.tv_name);
        tvName.setText(item.exam_type_name);

        //分数  成绩:+属性+分
        TextView tvScore = helper.getView(R.id.tv_score);
        tvScore.setText("成绩:" + item.exam_score + "分");


        //花费时间 花费时间:+属性+分
        TextView tvUseTime = helper.getView(R.id.tv_use_time);
        tvUseTime.setText("花费时间:" + getUseTime(Integer.parseInt(item.total_time)));

        //时间
        TextView tvTime = helper.getView(R.id.tv_time);
        tvTime.setText(item.exam_dt);
    }

    /**
     * 返回所用时间
     *
     * @param useTimes
     * @return
     */
    private String getUseTime(int useTimes) {
        String res = "";
        if (useTimes < 60) {
            //小于1分钟,显示秒
            res = useTimes + "秒";
        } else if (useTimes < 60 * 60) {
            //小于一小时,显示分秒
            int m = useTimes / 60;

            int s = useTimes % 60;

            res = m + "分" + s + "秒";
        } else {
            //大于一小时,显示时分秒
            int h = useTimes / (60 * 60); //获取小时

            int m = useTimes % (60 * 60) / 60; //获取分钟

            int s = useTimes % (60 * 60) % 60;//获取秒

            res = h + "小时" + m + "分" + s + "秒";
        }

        return res;
    }


    /**
     * 根据LessonID获取Unit单元的方法
     *
     * @param lessonid 7位的lessonid 1001001
     */
    private String getUnit(String lessonid) {
        String res = "";
        //截取Lessonid后4位
        String afterFourNum = lessonid.substring(3);

        //分别截取后4位的第一位和最后2位
        String index = afterFourNum.substring(0, 1);
        String twoNum = afterFourNum.substring(2);

        //计算单元
        res = ((Integer.parseInt(index) - 1) * 18 + Integer.parseInt(twoNum)) + "";

        return res;

    }

}
